package com.zg.assistant.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zg.assistant.service.QrCodeService;
import com.zg.assistant.utils.QrCodeUtils;
import com.zg.common.core.User;
import com.zg.common.core.constant.AssistantContants;
import com.zg.common.web.Req;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 二维码服务实现类
 * @author zg
 */
@Service
@RequiredArgsConstructor
public class QrCodeServiceImpl implements QrCodeService {

    @Override
    public String createQrCodeBase64(String uuid) {
        User currUser = Req.getCurrUser();
        if (currUser == null) {
            throw new RuntimeException("用户未登录");
        }

        // 获取用户名
        String userName = currUser.getUsername();

        // 生成移动端clientId
        String mobileClientId = AssistantContants.CLIENT_TYPE_APP + uuid + "-"+ userName;
        String qrCodeContent = AssistantContants.APP_WEBSOCKET_FLAG + mobileClientId;

        // 生成Base64格式二维码
        return QrCodeUtils.generateQrCodeBase64(qrCodeContent, 300, 300);
    }

}
